package com.exposit.smarthouse.dao.impl;

import org.hibernate.*;
import org.hibernate.criterion.*;
import org.springframework.orm.hibernate3.support.*;
import com.exposit.smarthouse.dao.*;
import com.exposit.smarthouse.obj.impl.*;


public class DaoImpl<T extends PersistenceEntity> extends HibernateDaoSupport implements Dao<T>
{
    @Override
    public void saveOrUpdate(T entity)
    {
        getHibernateTemplate().saveOrUpdate(entity);
    }

    @Override
    public void delete(T entity)
    {
        getHibernateTemplate().delete(entity);
    }

    @Override
    @SuppressWarnings("unchecked")
    public T findByIdentity(Long identity)
    {
        Criteria criteria = getSession().createCriteria(PersistenceEntity.class);
        criteria.add(Restrictions.eq(T.ATTR_IDENTITY, identity));

        return (T) criteria.uniqueResult();
    }
}
